package com.tchintech.pay.view.activity;

import android.app.Activity;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tchintech.pay.R;
import com.tchintech.pay.delegate.CodePayDelegate;
import com.tchintech.pay.frame.presenter.ActivityPresenter;
import com.tchintech.pay.utils.CreateQRImageTest;
import com.tchintech.pay.view.fragment.MainFragment;

/**
 * Created by Administrator on 2017/8/26 0026.
 * 二维码支付
 */

public class CodePayActivity extends ActivityPresenter<CodePayDelegate> implements View.OnClickListener {
    private ImageView iv_paycode;
    private String url;
    private CreateQRImageTest createQRImageTest;

    private TextView tv_lx;
    private String busCode = "";

    @Override
    protected void initView() {
        super.initView();
        iv_paycode = viewDelegate.getIv_paycode();
        viewDelegate.setTv_title("二维码收款");
        viewDelegate.setOnClickListener(this, R.id.iv_back, R.id.bt_code);
        tv_lx = viewDelegate.get(R.id.tv_lx);
        createQRImageTest = new CreateQRImageTest();
        createQRImageTest.createQRImage(url, iv_paycode);
        setCodeType();
    }

    private void setCodeType() {
        if (busCode.equals("3101")) {
            tv_lx.setText("微信");
            tv_lx.setTextColor(ContextCompat.getColor(this, R.color.colorWx));
        } else if (busCode.equals("3201")) {
            tv_lx.setText("支付宝");
            tv_lx.setTextColor(ContextCompat.getColor(this, R.color.colorZfb));
        }

        tv_lx.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        tv_lx.getPaint().setAntiAlias(true);//抗锯齿
    }


    @Override
    protected void initData() {
        super.initData();
        url = getIntent().getStringExtra("url");
        busCode = getIntent().getStringExtra("busCode");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.bt_code:
                //关闭2个页面
                MainFragment.listA.get(0).finish();
                MainFragment.listA.clear();
                finish();
                break;
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    protected Class<CodePayDelegate> getDelegateClass() {
        return CodePayDelegate.class;
    }
}
